package com.zxx.xin.shorthand.ui.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 单行垂直显示的TextView
 * Created by xin on 2018/3/15.
 */

@SuppressLint("AppCompatCustomView")
public class VerticalTextView extends TextView {

    public VerticalTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/jianshi_default.otf"));
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        if (TextUtils.isEmpty(text)){
            super.setText(text, type);
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < text.length() - 1; i++){
                sb.append(text.charAt(i)).append('\n');
            }
            sb.append(text.charAt(text.length() - 1));
            super.setText(sb, type);
        }
    }
}
